<?php

/**
 * RealisasiBk form.
 *
 * @package    alazhar
 * @subpackage form
 * @author     Ardhy Widodo
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class RealisasiBkForm extends BaseRealisasiBkForm {

    public function configure() {
        $subForm = new sfForm();
        $this->widgetSchema['waktu_mulai'] = new sfWidgetFormInputText(array(), array('id' => 'datetime_mulai'));
        $this->widgetSchema['waktu_akhir'] = new sfWidgetFormInputText(array(), array('id' => 'datetime_akhir'));
        for ($i = 0; $i < 5; $i++) {
            $fileRealisasiBk = new FileRealisasiBk();
            $fileRealisasiBk->RealisasiBk = $this->getObject();
            $form = new FileRealisasiBkForm($fileRealisasiBk);
            $subForm->embedForm($i, $form);
        }
        $this->embedForm('newFile', $subForm);
        $this->widgetSchema->setLabel('newFile', 'Dokumen Realisasi');
    }

    public function saveEmbeddedForms($con = null, $forms = null) {
        if (null === $forms) {
            $files = $this->getValue('newFile');
            $forms = $this->embeddedForms;
            foreach ($this->embeddedForms['newFile'] as $name => $form) {
                if (!isset($files[$name])) {
                    unset($forms['newFile'][$name]);
                }
            }
        }
        parent::saveEmbeddedForms($con, $forms);
    }

}
